﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 设计模式之禅.建造者模式
{
    public class Product
    {
        private int value;
        public void Add()
        {
            value++;
        }
        public int Say()
        {
            return value;
        }
    }

    public abstract class Builder
    {
        public abstract void BuildPartA();
        public abstract void BuildPartB();
        public abstract Product GetProduct();
    }
    public class ConcreteBuilderA : Builder
    {
        private Product _p = new Product();
        public override void BuildPartA()
        {
            _p.Add();
        }
        public override void BuildPartB()
        {
            _p.Add();
            _p.Add();
        }
        public override Product GetProduct()
        {
            return _p;
        }

    }
    public class ConcreteBuilderB : Builder
    {
        private Product _p = new Product();
        public override void BuildPartA()
        {
            _p.Add();
        }
        public override void BuildPartB()
        {
            _p.Add();
        }
        public override Product GetProduct()
        {
            return _p;
        }

    }

    public class Director
    {
        public Product Construct(Builder builder)
        {
            builder.BuildPartA();
            builder.BuildPartB();
            return builder.GetProduct();
        }
    }


}
